home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 43 / Amiga Format CD43 (1999)(Future Publishing)(GB)(Track 1 of 2)[!][issue 1999-09].iso / -serious- / programming / other / guigfxlib / doc / examples < prev    next >
Text File  |  1999-06-14  |  4KB  |  195 lines

  1.  
  2. guigfx.library
  3. list of examples
  4.  
  5. 1. Load a single picture and draw it to a window
  6. 2. Load a picture and use it as a bitmap
  7. 3. Create a drawhandle for multiple pictures
  8. 4. Create a drawhandle with a static palette
  9. 5. Rendering varying truecolor graphics realtime
  10.  
  11.  
  12.  
  13. 1. Load a single picture and draw it to a Window
  14. ------------------------------------------------
  15.  
  16.     APTR picture = NULL, psm = NULL, drawhandle = NULL;
  17.  
  18.  
  19. initialization:
  20.  
  21.  
  22.     picture = LoadPicture(filename, TAG_DONE);
  23.     psm = CreatePenShareMap(TAG_DONE);
  24.  
  25.     if (psm && picture)
  26.     {
  27.         if (AddPicture(psm, picture, TAG_DONE))
  28.         {
  29.             drawhandle = ObtainDrawHandle(psm, window->RPort,
  30.                 screen->ViewPort.ColorMap, TAG_DONE);
  31.         }
  32.  
  33.         DeletePenShareMap(psm);    /* no longer needed */
  34.     }
  35.  
  36.     if (drawhandle)
  37.     {
  38.         DrawPicture(drawhandle, picture, x, y, TAG_DONE);
  39.     }
  40.  
  41.  
  42. notes:
  43.  
  44. You may remove the picture now using DeletePicture(), but do
  45. not release the drawhandle as long as the picture is
  46. visible. Before you release the drawhandle, clear the
  47. RastPort where the picture is located.
  48.  
  49.  
  50. closedown:
  51.  
  52.     DeletePicture(picture);
  53.     ReleaseDrawHandle(drawhandle);
  54.         
  55.  
  56.  
  57.  
  58. 2. Load a picture and use it as a bitmap
  59. ----------------------------------------
  60.  
  61. You should prefer using BitMaps over DrawPicture(), when the
  62. window is of type SIMPLE_REFRESH and the window contents may
  63. need to get refreshed.
  64.  
  65.  
  66.     APTR picture = NULL, psm = NULL, drawhandle = NULL;
  67.     struct BitMap *bm = NULL;
  68.  
  69.  
  70. initialization:
  71.  
  72.  
  73.     picture = LoadPicture(filename, TAG_DONE);
  74.  
  75.     if (picture)
  76.     {
  77.         psm = CreatePenShareMap(TAG_DONE);
  78.     }
  79.  
  80.     if (psm)
  81.     {
  82.         AddPicture(psm, picture, TAG_DONE);
  83.  
  84.         drawhandle = ObtainDrawHandle(psm, window->RPort,
  85.             screen->ViewPort.ColorMap, TAG_DONE);
  86.         }
  87.     }
  88.     
  89.     if (drawhandle)
  90.     {
  91.         bm = CreatePictureBitMap(drawhandle, picture, TAG_DONE);
  92.     }
  93.     
  94.     DeletePicture(picture);  /* no need to maintain these
  95.     DeletePenShareMap(psm);     objects any longer */
  96.  
  97.  
  98. draw / refresh:
  99.  
  100.     
  101.     if (bm)
  102.     {
  103.         BltBitMapRastPort(bm, srcx, srcy, window->RPort,
  104.             dstx, dsty, width, height, 0xc0);
  105.     }
  106.  
  107.  
  108. closedown:
  109.  
  110.  
  111.     FreeBitMap(bm);    /* graphics.library */
  112.     ReleaseDrawHandle(drawhandle);
  113.  
  114.  
  115.  
  116. 3. Create a drawhandle for multiple pictures
  117. --------------------------------------------
  118.  
  119. initialization:
  120.  
  121.     picture1 = LoadPicture(filename1, TAG_DONE);
  122.     picture2 = LoadPicture(filename2, TAG_DONE);
  123.     picture3 = LoadPicture(filename3, TAG_DONE);
  124.  
  125.     psm = CreatePenShareMap(TAG_DONE);
  126.  
  127.     if (psm && picture1 && picture2 && picture3)
  128.     {
  129.         AddPicture(psm, picture1, TAG_DONE);
  130.         AddPicture(psm, picture2, TAG_DONE);
  131.         AddPicture(psm, picture3, TAG_DONE);
  132.  
  133.         drawhandle = ObtainDrawHandle(psm, window->RPort,
  134.             screen->ViewPort.ColorMap, TAG_DONE);
  135.         }
  136.     }
  137.     
  138.     DeletePenShareMap(psm);
  139.     
  140.     etc.
  141.  
  142.  
  143.  
  144. 4. Create a drawhandle with a static palette
  145. --------------------------------------------
  146.  
  147. Typical application: WWW browser
  148.  
  149. A static palette is recommended if your application has no
  150. idea what colors will appear in the imagery, or when their
  151. contents may vary. Use static palettes preferrably on a
  152. seperate screen.
  153.  
  154.  
  155. initialization:
  156.  
  157.     drawhandle = ObtainDrawHandle(NULL, window->RPort,
  158.             screen->ViewPort.ColorMap, TAG_DONE);
  159.  
  160.     /* NULL = no pen-sharemap available - a static palette
  161.     for the whole RGB space will be allocated */
  162.     
  163.     etc.
  164.  
  165.  
  166.  
  167. 5. Render truecolor graphics realtime
  168. -------------------------------------
  169.  
  170. Typical applications: Colorful realtime spectrum analyzer,
  171. animation in a Workbench window, etc.
  172.  
  173.  
  174. When your application needs to render varying truecolor
  175. graphics, create a 'direct'-drawhandle:
  176.  
  177.     APTR ddh;
  178.  
  179.     ddh = CreateDirectDrawHandle(drawhandle, sourcewidth,
  180.         sourceheight, destwidth, destheight, NULL);
  181.  
  182. As you can see, a 'direct'-drawhandle is derived from an
  183. already existing drawhandle. It allows to draw RGB data with
  184. very low overhead:
  185.  
  186.     DirectDrawTrueColor(ddh, rgbdata, x,y, TAG_DONE);
  187.  
  188. closedown:
  189.  
  190.     DeleteDirectDrawHandle(ddh);
  191.     ReleaseDrawHandle(drawhandle);
  192.     
  193.     etc.
  194.  
  195.